/**
 * Project:   dtu.fmes.googleloon
 * File:      ConstantPowerDrawSimulationLink.java
 * License: 
 *            This file is licensed under GNU General Public License version 3
 *            http://www.gnu.org/licenses/gpl-3.0.txt
 *
 * Copyright: Bartosz Cichecki [ cichecki.bartosz@gmail.com ]
 * Date:      Oct 23, 2013
 */

package dtu.fmes.loon.simulation.processors;

import java.util.concurrent.TimeUnit;

import dtu.fmes.loon.model.Balloon;
import dtu.fmes.loon.model.ConstantBalloonValues;

/**
 * This simulation link reduces the amount of power in the battery by the amount
 * of power drawn by modules.
 * 
 * @author Bartosz Cichecki, Nicolai Sonne
 * 
 */
public class ConstantPowerDrawSimulationLink extends SimulationLink {

	@Override
	public void run() {
		long dischargeTime = css.getSimulation().getSimulationInterval();

		Double totalPowerDraw = 0.0;

		ConstantBalloonValues cbv = css.getConstantBalloonValues();

		totalPowerDraw += cbv.getGps().getPowerUsage();
		totalPowerDraw += cbv.getCommunication().getPowerUsage();
		totalPowerDraw = totalPowerDraw * dischargeTime / TimeUnit.HOURS.toSeconds(1);

		for (Balloon b : css.getBalloons()) {
			if (b.isAlive()) {
				b.setCurrentBatteryCapacity(b.getCurrentBatteryCapacity() - totalPowerDraw);
			}
		}
	}

}
